<template>
  <div class="xtx-goods-page" v-if="goods.categories">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread separator="/">
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem :to="`/category/${goods.categories[1].id}`">
          {{ goods.categories[1].name }}
        </XtxBreadItem>
        <XtxBreadItem :to="`/category/sub/${goods.categories[0].id}`">
          {{ goods.categories[0].name }}
        </XtxBreadItem>
        <XtxBreadItem to="/">
          {{ goods.name }}
        </XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
        <!-- 图片预览区 -->
        <div class="media">
          <GoodsImage :images="goods.mainPictures" />
          <!-- 销量组件 -->
          <GoodsSales :goods="goods" />
        </div>
        <!-- 商品信息区 -->
        <div class="spec">
          <!-- 信息组件 -->
          <GoodsName :goods="goods" />
          <!-- sku组件 -->
          <GoodsSku :goods="goods" @change="skuChange" />
          <!-- 数据组件 -->
          <XtxNumbox v-model="num" />
          <!-- 按钮组件 -->
          <XtxButton type="primary" style="margin-top: 20px"
            >加入购物车</XtxButton
          >
        </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <GoodsTabs />
          <!-- 注意事项 -->
          <!-- <div class="goods-warn"></div> -->
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside">
          <GoodsHot :type="1" />
          <GoodsHot :type="2" />
          <GoodsHot :type="3" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { findGoods } from '@/api/goods'
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import GoodsImage from './components/goods-image.vue'
import GoodsName from './components/goods-name.vue'
import GoodsSales from './components/goods-sales.vue'
import GoodsSku from './Sku/index.vue'
import GoodsTabs from './components/goods-tabs.vue'
import GoodsHot from './components/goods-hot.vue'

export default {
  name: 'XtxGoodsPage',
  components: {
    GoodsImage,
    GoodsName,
    GoodsSales,
    GoodsSku,
    GoodsTabs,
    GoodsHot
  },
  setup () {
    const route = useRoute()
    const goods = ref({})
    async function getGoods () {
      const res = await findGoods(route.params.id)
      // console.log(res)
      goods.value = res.result
    }
    onMounted(() => {
      getGoods()
    })
    function skuChange (sku) {
      console.log(sku)
    }
    // 商品数量
    const num = ref(1)
    return { goods, skuChange, num }
  }
}
</script>

<style scoped lang='less'>
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
